package com.itheima.datastructure.stack;

public class E01Leetcode20 {
    public boolean isVaild(String s){
        ArrayStack<Character> stack=new ArrayStack<>(s.length());
        for(int i=0;i<s.length();i++){
            char c=s.charAt(i);
            if(c=='('){
                stack.push(')');
            }else if(c=='{'){
                stack.push('}');
            }else if(c=='['){
                stack.push(']');
            }else{
                if(c==stack.peek()){
                    stack.pop();
                }else{
                    return false;
                }
            }
        }
        return stack.isEmpty();
    }

    public static void main(String[] args) {
        E01Leetcode20 s=new E01Leetcode20();
        System.out.println(s.isVaild("([{}])"));
        System.out.println(s.isVaild("()[]{}"));
        System.out.println(s.isVaild("()"));
    }
}
